package cn.com.landsky.camera.service.impl;

import cn.com.landsky.camera.common.base.BaseServiceImpl;
import cn.com.landsky.camera.entity.Camera;
import cn.com.landsky.camera.mapper.CameraMapper;
import cn.com.landsky.camera.service.CameraService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author qing.yunhui 
 * @Since 2011-2019
 * @create 2019-01-03 14:04:03
 * @history
 */
@Service("cameraService")
@Slf4j
public class CameraServiceImpl extends BaseServiceImpl<Camera,Long> implements CameraService {

    @Autowired
    CameraMapper cameraMapper;

    @Override
    public int addCamera(Camera model) {
        if(null==model){
            log.error("=====================>要添加的设备不能为空!!!");
            throw new RuntimeException("要添加的设备不能为空!!!");
        }
        Camera camera=cameraMapper.getCameraByDeviceNumber(model.getDeviceNumber());
        if(null!=camera){
            log.error("=====================>设备编号:{}设备，已经存在，请勿重复添加!!!");
            return 0;
        }
        return cameraMapper.insert(model);
    }
}